/**
 * @Author YuanYuan
 * @Date 2022/10/17
 * @Time 16:14
 */
public class TestDemo1 {


    public static void main(String[] args) {
        Object locker1 = new Object();
        Object locker2 = new Object();

        Thread thread1 = new Thread(() -> {
            synchronized (locker1) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t1获取locker1成功!");
                System.out.println("t1尝试获取locker2");
                synchronized (locker2) {
                    System.out.println("t1获取两把锁成功!");
                }
            }
        });

        Thread thread2 = new Thread(() -> {
            synchronized (locker1) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t2获取locker1成功!");
                System.out.println("t2尝试获取locker2");
                synchronized (locker2) {
                    System.out.println("t2获取两把锁成功!");
                }
            }
        });

        thread1.start();
        thread2.start();

    }
}
